package com.example.intelligentattendancesystem.mapping;

import com.example.intelligentattendancesystem.pojo.History;
import com.example.intelligentattendancesystem.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface HistoryMapping {
    /**
     * 新增用户打卡记录
     * @param history 打卡记录
     * @return 修改的条数
     */
    @Insert("insert into t_history values(#{id}, #{userId}, #{signInTime},#{signOutTime},#{signPosition})")
    int insertHistory(History history);

    /**
     * 通过ID查询用户的打卡记录
     * @param userId
     * @return
     */
    @Select("select id,user_id as userId , sign_in_time as signInTime,sign_out_time as signOutTime,sign_position as signPosition from t_history where user_id = #{userId} order by signInTime ")
    List<History> selectHistoryByUserId(int userId);

    @Select("select id,user_id as userId , sign_in_time as signInTime,sign_out_time as signOutTime,sign_position as signPosition from t_history where user_id = #{userId} and sign_in_time like concat(#{today},'%')")
    List<History> selectHistoryByUserIdInToday(int userId, String today);
    /**
     * 通过账号删除用户的打卡记录
     * @param userId
     * @return 修改的条数
     */
    @Delete("delete from t_history where user_id = #{userId}")
    int deleteHistoryByUserId(int userId);

    /**
     * 查询所有用户的所有打卡记录
     * @return 打卡记录列表
     */
    @Select("select id,user_id as userId , sign_in_time as signInTime,sign_out_time as signOutTime,sign_position as signPosition from t_history")
    List<History> selectAllHistory();
}
